<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名字" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型" clearable size="small">
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="举报/反馈" label-width="auto" prop="status">
        <el-select v-model="queryParams.status" placeholder="类型" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="处理状态" label-width="auto" prop="isHandle">
        <el-select v-model="queryParams.isHandle" placeholder="处理状态" clearable size="small">
          <el-option
            v-for="dict in isHandleOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['men:menFeedback:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['men:menFeedback:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['men:menFeedback:remove']"
        >删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['men:menFeedback:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="menFeedbackList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="意见反馈id" align="center" prop="id" /> -->
      <el-table-column label="名字" align="center" prop="name" :show-overflow-tooltip="true"/>
      <el-table-column label="手机号" align="center" prop="phone" :show-overflow-tooltip="true"/>
      <el-table-column label="反馈内容" align="center" prop="content" :show-overflow-tooltip="true"/>
      <el-table-column label="类型" align="center" prop="type" :formatter="typeFormat" />
      <el-table-column label="相关" align="center" prop="backId" :show-overflow-tooltip="true" v-if="false"/>
      <el-table-column label="相关名字" align="center" prop="backName" :show-overflow-tooltip="true"  >
        <template slot-scope="scope">
          <el-button type="text" size="small" v-if="scope.row.type==2">{{scope.row.backName}}</el-button>
          <el-button type="text" size="small" @click="clickData(scope.row)" v-else>{{scope.row.backName}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="举报/反馈" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="创建时间" align="center" prop="caAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.caAt) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理状态" align="center" prop="isHandle" :formatter="isHandleFormat" />
      <!-- <el-table-column label="修改时间" align="center" prop="upAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.upAt) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['men:menFeedback:edit']"
          >修改</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['men:menFeedback:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleRecommend(scope.row)"
            v-hasPermi="['men:menFeedback:edit']"
          >处理状态</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改意见反馈对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名字" prop="name">
          <el-input v-model="form.name" placeholder="请输入名字" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="反馈内容" prop="content">
          <el-input v-model="form.content" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="0商品1供需2其他" prop="type">
          <el-select v-model="form.type" placeholder="请选择0商品1供需2其他">
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="相关id" prop="backId">
          <el-input v-model="form.backId" placeholder="请输入相关id" />
        </el-form-item>
        <el-form-item label="0意见反馈1举报信息">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="创建时间" prop="caAt">
          <el-date-picker clearable size="small"
                          v-model="form.caAt"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改时间" prop="upAt">
          <el-date-picker clearable size="small"
                          v-model="form.upAt"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择修改时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="0默认1删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入0默认1删除" />
        </el-form-item>
        <el-form-item label="处理状态" prop="isHandle">
          <el-input v-model="form.isHandle" placeholder="处理状态" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="isHandle" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="处理状态" prop="isHandle" label-width="100">
          <el-radio-group v-model="form.isHandle">
            <el-radio
              v-for="dict in isHandleOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listMenFeedback, getMenFeedback, delMenFeedback, addMenFeedback, updateMenFeedback, exportMenFeedback } from "@/api/men/menFeedback";

  export default {
    name: "MenFeedback",
    components: {
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 意见反馈表格数据
        menFeedbackList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 0商品1供需2其他字典
        typeOptions: [],
        // 0意见反馈1举报信息字典
        statusOptions: [],
        // 处理状态（0：未处理 1：已处理）信息字典
        isHandleOptions: [],
        // 处理状态弹出层
        isHandle: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          type: null,
          status: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          isHandle: [
            { required: true, message: "处理状态不能为空", trigger: "blur" }
          ],
          status: [
            { required: true, message: "0意见反馈1举报信息不能为空", trigger: "blur" }
          ],
          caAt: [
            { required: true, message: "创建时间不能为空", trigger: "blur" }
          ],
          delFlag: [
            { required: true, message: "0默认1删除不能为空", trigger: "blur" }
          ]
        }
      };
    },
    created() {
      this.getList();
      this.getDicts("men_feedback_type").then(response => {
        this.typeOptions = response.data;
      });
      this.getDicts("men_feedback_status").then(response => {
        this.statusOptions = response.data;
      });
      this.getDicts("men_feedback_isHandle").then(response => {
        this.isHandleOptions = response.data;
      });
    },
    methods: {
      /** 查询意见反馈列表 */
      getList() {
        this.loading = true;
        listMenFeedback(this.queryParams).then(response => {
          this.menFeedbackList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 0商品1供需2其他字典翻译
      typeFormat(row, column) {
        return this.selectDictLabel(this.typeOptions, row.type);
      },
      // 0意见反馈1举报信息字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.status);
      },
      // 处理状态（0：未处理 1：已处理）字典翻译
      isHandleFormat(row, column) {
        return this.selectDictLabel(this.isHandleOptions, row.isHandle);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.isHandle = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          name: null,
          phone: null,
          content: null,
          type: null,
          backId: null,
          status: 0,
          isHandle: null,
          caAt: null,
          upAt: null,
          delFlag: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      clickData(row) {
        console.log(row)
        if(row.type==0){
          //window.open("https:www.baidu.com");
          window.open("http://mall.tbmcloud.com.cn/home/detail?id=" + row.backId);
        }else if(row.type==1){
          // window.open("https:www.qq.com");
          window.open("http://mall.tbmcloud.com.cn/home/releaseitem?id=" + row.backId);
        }else{
          "";
        }
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加意见反馈";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getMenFeedback(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改意见反馈";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateMenFeedback(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.isHandle = false;
                this.getList();
              });
            } else {
              addMenFeedback(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.isHandle = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除意见反馈选中数据', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delMenFeedback(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 处理状态按钮操作 */
      handleRecommend(row) {
        this.reset();id
        const id = row.id || this.ids
        getMenFeedback(id).then(response => {
          this.form = response.data;
          this.isHandle = true;
          this.title = "处理状态";
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有意见反馈数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportMenFeedback(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      }
    }
  };
</script>
